var data = "";

function do_register()
{
	var user = document.getElementById("user").value;
	var passwd = document.getElementById("passwd").value;
	//alert("user："+user+"   passwd："+passwd);
	if(user == "" || passwd == "")
		alert("请输入注册的用户名和密码信息");
	else
	{
		if(user == "admin" || user == "lanxue")
			alert("不允许注册管理员！");
		else
		{
			data = "register:";
			data += user;
			data += ",";
			data += passwd;
			deal_request();
		}	
		//document.getElementById("passwd").value = "";
		//alert("您输入的用户名或密码错误，请重新输入！");
	}
}

function get_xmlreq(){
	var xmlhttp = null;
	if(window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}

function deal_request(){
	var xmlhttp = get_xmlreq();
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
            var ret = xmlhttp.responseText;
			//alert(ret);
			var buf = ret.split(",");//logonreply,http://10.0.112.114/Arg_data.html
									//logonreply,用户或密码错误
			if(buf[0] == "logonreply")//登录应答
			{
				if(buf[1].substr(0, 7) == "http://")
				{
					window.location.href = buf[1];
				}
				else
					alert(buf[1]);
			}
			else if(buf[0] == "register")//登录应答
			{
					alert(buf[1]);
			}
			else 
				alert(ret);
		}
	}
	//myurl = "/cgi-bin/Arg_data.cgi?Sign_in:admin,123456";
	//myurl = "/cgi-bin/Arg_data.cgi?register:lanxue,123456";
	var myurl = "/cgi-bin/Arg_data.cgi?";
    myurl += data;
    //alert(myurl);
	xmlhttp.open("GET",myurl,true);
	xmlhttp.setRequestHeader("If-Modified-Since","0");
    xmlhttp.send();
}

function init_getdata(){
	
}

function do_login(argument) {
	// 获取用户名和密码
	var user = document.getElementById("user").value;
	var passwd = document.getElementById("passwd").value;
	//alert("user："+user+"   passwd："+passwd);
	if(user == "" || passwd == "")
		alert("请输入用户名和密码！");
	else
	{
		data = "Sign_in:";
		data += user;
		data += ",";
		data += passwd;
		deal_request();
		document.getElementById("passwd").value = "";
		//alert("您输入的用户名或密码错误，请重新输入！");
	}
}
